﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace Scheduling_Problem16_2
{
    public partial class Form1 : Form
    {
        TextWriter _writer = null;
        public Form1()
        {
            InitializeComponent();
            _writer = new TextBoxStreamWriter(txtConsole);
            Console.SetOut(_writer);
            //Console.WriteLine("Now redirecting output to the text box");
        }
        private void Form1_Load(object sender, EventArgs e)
        {
           
        }
        private void AddTrivialData_Click(object sender, EventArgs e)
        {
            TaskList.DataSource = null;
            Random r = new Random();
            for (int i = 0; i <3; i++)
            {
                Scheduler.Instance.AllTasks.Add(new Task(r.Next(1,10)));
            }
            for (int j = 0; j < Scheduler.Instance.AllTasks.Count; j ++)
            {
                Scheduler.Instance.AllTasks[j].Index = j + 1;
            }
            TaskList.DataSource = Scheduler.Instance.AllTasks;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OrderedTasks.DataSource = null;
            List<Task> newData = SchedulingFunctions.OrderedTasks(Scheduler.Instance.AllTasks);
            OrderedTasks.DataSource = newData;
            //float avg = 0;
            //float
            float avgTime = 0;
            for (int i = 0; i < newData.Count; i++)
            {
                avgTime += newData[i].CompletionTime;
            }
            if (newData.Count != 1)
                avgTimeHolder.Text = "" + avgTime / newData.Count;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TaskList.DataSource = null;
            Random r = new Random();
            for (int i = 0; i < 3; i++)
            {
                Scheduler.Instance.AllTasks.Add(new Task(r.Next(1, 10), r.Next(1,10)));
            }
            for (int j = 0; j < Scheduler.Instance.AllTasks.Count; j++)
            {
                Scheduler.Instance.AllTasks[j].Index = j + 1;
            }
            TaskList.DataSource = Scheduler.Instance.AllTasks;
        }

        private void txtConsole_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
